package com.example.tests;

import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.example.fw.Contact;

public class ContactRemovalTests extends TestBase{
	
	@BeforeMethod
	public void createContactBeforeTest() {
		Contact contact = new Contact().setFirstname("tester").setLastname("tester");
		app.getContactHelper().createContact(contact);
	}
	
	@Test
	public void deleteSomeContact() {
		List<Contact> oldContacts = app.getContactHelper().getContacts();
	    Random rnd = new Random();
	    int index = rnd.nextInt(oldContacts.size() + 1);
		app.getContactHelper().deleteContact(index + 1);
		List<Contact> newContacts = app.getContactHelper().getContacts();
		Collections.sort(oldContacts);
		oldContacts.remove(index);
		Assert.assertEquals(oldContacts, newContacts);
	}
}
